﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace SalaryChannel.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PublicService
    {
        [OperationContract]
        public List<PublicInfor> GetPublicInfor()
        {
            try
            {
                using (DataClassesQueryDataContext context = new DataClassesQueryDataContext())
                {
                    var query = context.PublicInfor.Where(a => a.Expire_Date >= DateTime.Now)
                        .Where(b => b.IsValid == '1');
                    if (query.Any())
                    {
                        return query.OrderByDescending(c => c.Create_Date).ToList();
                    }
                    return new List<PublicInfor>();
                }
            }
            catch (Exception e)
            {
                LogManager.Write("PublicService.GetPublicInfor:" + e.Message);
                return null;
            }
        }
    }
}
